home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / CustomWriterGX / ChooserLDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  5.2 KB  |  191 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         ChooserLDEF.c
  4.  
  5.     DESCRIPTION
  6.         Contains code for LDEF resource used by the Chooser.
  7.  
  8.     COPYRIGHT
  9.         Copyright © 1995 Apple Computer, Inc.
  10.         All rights reserved.
  11.     
  12.     Modification history
  13.         06/14/96 - cn             -    Updated to support Universal Interfaces 2.1.
  14.         
  15.         10/04/95 - David Hayward -    Version 1.0.4 modified code so that
  16.                                     the driver can be build under MPW,
  17.                                     Metrowerks, and Symantec.  In general,
  18.                                     all that was required to do this was 
  19.                                     to add an inline-assembly jumptable
  20.                                     and to store all globals off of the
  21.                                     message manager instance context.
  22.                                     Also made a few changes so that the
  23.                                     driver can be rebuilt to support any
  24.                                     resolution by changing the #defines
  25.                                     kResolution and kPatStretch in
  26.                                     "CommonDefines.h"
  27.  
  28.         06/14/95 - Dave Hersey -    Version 1.0.3 to fix a bug in
  29.                                     CustomBufferingAndIO.c when creating
  30.                                     high-res PICTs, and to make the size
  31.                                     of buffers more flexible.
  32.  
  33.         05/26/95 - Dave Hersey -    Version 1.0.2 to add the new 'outp'
  34.                                     desktop printer resource in NewApp.c.
  35.  
  36.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  37.                                     CustomBufferingAndIO.c.
  38.  
  39.         01/14/95 - Dave Hersey -    Created from the shell of a hollowed-out
  40.                                     ImageWriter driver.
  41. */
  42.  
  43. #include <Lists.h>
  44. #include <Types.h>
  45. #include <Resources.h>
  46. #include <QuickDrawText.h>
  47. #include <ToolUtils.h>
  48. #include <LowMem.h>
  49. #include <GXPrinting.h>
  50. #include "ChooserLDEF.h"
  51.  
  52.  
  53. pascal void        main (short message, Boolean select, Rect *theRect,
  54.                      Cell theCell, short dataOffset, short dataLen, ListHandle theList);
  55.  
  56.  
  57. /*    -----------------------------------------------------------------------
  58.     LDEF is our driver's Chooser LDEF.
  59.  
  60.     This is an LDEF that simply plots an icon, and lets the user "Create."
  61.  
  62.     -----------------------------------------------------------------------    */
  63.  
  64. pascal void main (
  65.     short         message,        // What operation to perform on list
  66.     Boolean     select,            // Is this cell to be selected or not?
  67.     Rect        *theRect,        // Rectangle of this cell, clipped to window
  68.     Cell        theCell,        // Which cell this is
  69.     short        dataOffset,        // Offset into data for this cell
  70.     short        dataLen,        // Length of data for this cell
  71.     ListHandle    theList)        // The list to act upon
  72. {
  73. #pragma unused (theCell, dataOffset, dataLen)
  74.  
  75.         Handle        cicnHdl;
  76.         Rect        iconRect;
  77.         char*        userPrompt;
  78.  
  79.  
  80.         userPrompt = (char *) "\pPrint to Disk";
  81.  
  82.         switch (message)
  83.         {
  84.             case lInitMsg:
  85.                 {
  86.                     Cell    aCell;
  87.                     
  88.                     aCell.h = 0;
  89.                     aCell.v = 1;
  90.                     (*theList)->userHandle = (Handle) GetCIcon(r_ChooserIcon);
  91.     
  92.                     if ((*theList)->userHandle)
  93.                     {
  94.                         DetachResource((*theList)->userHandle);
  95.                         LSetCell((Ptr) &userPrompt[1], userPrompt[0], aCell, theList);
  96.                         LSetSelect(true, aCell,theList);
  97.                     }
  98.                 }
  99.                 break;
  100.                 
  101.             case lCloseMsg:
  102.                 if ((*theList)->userHandle)
  103.                 {
  104.                     DisposeCIcon((CIconHandle) (*theList)->userHandle);
  105.                     (*theList)->userHandle = nil;
  106.                 }
  107.                 break;
  108.  
  109.             case lHiliteMsg:
  110.             case lDrawMsg:
  111.                 cicnHdl = (*theList)->userHandle;
  112.                 if (cicnHdl == nil) break;
  113.                 
  114.                 // draw the cell as an icon
  115.                 // center the icon rect on the list with a top margin of 10 pixels
  116.  
  117.                 iconRect.top = theRect->top + 10;
  118.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  119.                 iconRect.bottom = iconRect.top + 32;
  120.                 iconRect.right = iconRect.left + 32;
  121.                     
  122.                     
  123.                 // draw the icon
  124.  
  125.                 if (cicnHdl != nil)
  126.                     PlotCIcon(&iconRect, (CIconHandle) cicnHdl);
  127.                                 
  128.                 // Get the general area under the icon in which to draw the label
  129.  
  130.                 iconRect.left = theRect->left + 2;
  131.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  132.                 iconRect.top = iconRect.bottom + 2;
  133.                 iconRect.bottom = theRect->bottom;
  134.         
  135.                 // use a nice small font for the label            
  136.  
  137.                 TextFont(applFont);
  138.                 TextSize(9);
  139.                     
  140.                 {
  141.                     short            labelWidth;
  142.                     short            rectWidth;
  143.                     short            labelHeight;
  144.                     FontInfo        theInfo;
  145.                     unsigned char    theHilightMode;
  146.                     
  147.     /*    Get rid of any previous label, compute the height of the new label,
  148.         compute where to draw the text, truncate the string to fit within the box,
  149.         compute the new width of the string, center the string, and draw it.
  150.     */
  151.                     EraseRect(&iconRect);
  152.                     iconRect.top += 2;
  153.                         
  154.                     GetFontInfo(&theInfo);
  155.                     labelHeight = theInfo.ascent +theInfo.leading;
  156.                 
  157.                     iconRect.bottom = iconRect.top + labelHeight;
  158.                     rectWidth = iconRect.right-iconRect.left;
  159.                     
  160.     // Not very localizable...  Use resources in the real world.
  161.  
  162.                     TruncString(rectWidth, (unsigned char *) userPrompt, smTruncEnd);
  163.                     labelWidth = StringWidth((unsigned char const *) userPrompt);
  164.                 
  165.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  166.                     MoveTo(iconRect.left, iconRect.bottom);
  167.                     DrawString((unsigned char const *) userPrompt);
  168.  
  169.     // If selecting the icon, highlight the text.
  170.  
  171.                     if (select)
  172.                     {
  173.                         iconRect.right = iconRect.left + labelWidth;
  174.                         iconRect.bottom += theInfo.descent;
  175.                         
  176.                         InsetRect(&iconRect, -1, -1);
  177.                         
  178.                         theHilightMode = LMGetHiliteMode();
  179.                         BitClr(&theHilightMode, pHiliteBit);
  180.                         LMSetHiliteMode(theHilightMode);
  181.                         InvertRect(&iconRect);
  182.                     }
  183.  
  184.                     TextFont(applFont);
  185.                     TextSize(0);
  186.                 }
  187.                 break;
  188.         }
  189. }
  190.  
  191.